﻿//this class just give interface for thread use
//it use bridge pattern to give low-coupling function

#ifndef GTHREAD_H
#define GTHREAD_H

class GThreadImpl;

class GThread
{
public:
	virtual ~GThread();

	void start();
	void join();

	static void sleep(long mseconds);

	virtual void stop();

	virtual void run() = 0;

protected:
	GThread();

private:
	GThreadImpl* m_threadImpl;
};

template <typename T>
class GThreading : public GThread
{
public:
    typedef void (T::*Method)();

    GThreading(T* runnable, Method runFunc) :
    m_runnable(runnable), m_runFunc(runFunc)
    {
    }

    ~GThreading()
    {
    }

private:
    void run()
    {
        (m_runnable->*m_runFunc)();
    }

    T* m_runnable;
    Method m_runFunc;
};

#endif
